home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11592 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: solon.com!not-for-mail
  2. From: kremser@sbox.tu-graz.ac.at (Herbert Kremser)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Followup-To: comp.lang.c,comp.lang.c.moderated
  6. Date: 25 Mar 1996 06:27:04 -0600
  7. Organization: Graz University of Technology, Austria
  8. Sender: clc@solutions.solon.com
  9. Approved: clc@solutions.solon.com
  10. Message-ID: <4j63eo$3lo@solutions.solon.com>
  11. References: <4j06gm$7oa@solutions.solon.com>
  12. NNTP-Posting-Host: solutions.solon.com
  13. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  14.  
  15. Reed R. Mangino (mangino@planet.net) wrote:
  16. : Could someone please straighten me out on this:
  17. : 1) const int *p = 10;
  18. :     p is a constant pointer to an int, right? While p can be made to
  19. :     point to something else, *p can never be assigned to, right?
  20.  
  21. correct
  22. btw, the "= 10" part will cause undefined, and most probably silly, behavior.
  23.  
  24. : 2) int *const p;
  25. :     p is a pointer to an integer.  *p can be assigned to, but p can
  26. :     never be made to point to another address in memory, right?
  27.  
  28. correct
  29.  
  30. : 3) int const *p;
  31. :     What the heck is this?  I can't find anything like this in my 
  32. :     books, but my compiler thinks everything is hunky doory!???
  33.  
  34. it's the same as  const int *p;
  35.  
  36. const refers always to the thing on it's left side. If there is nothing
  37. further left, it refers to the leftmost thing.
  38.  
  39. Therefore i prefer
  40.  
  41. int const i = 10;
  42. over
  43. const int i = 10;
  44.  
  45. most of the time.  :-)
  46.  
  47.  
  48. Herbert
  49. -- 
  50. Herbert Kremser                                      |  "On the Internet,
  51. kremser@flinux.tu-graz.ac.at                         |   nobody knows
  52. kremser@sbox.tu-graz.ac.at                           |   you're a dog." 
  53.